$(function(){
	$.ajax({
		type:"get",
		url:"json/xqy.json",
		async:true,
		success:function(mag){
		   	   		var data = mag.data
		   	   		var str =""
		   	   		var imgb = ""
		   	   		var imgs = ""
		   	   		var pri =''
		   	   		var bu =""
		   	   		var ba =""
		   	   		var jifen =""
		   	   		var fdj = ''
		   	   		for(var i= 0;i<data.length;i++){
		   	   			if(data[i].id === getCookie('dataid')){
		                 str +=data[i].name
		                 imgb +='<ul>'
		                 imgb +="<li><img src='"+data[i].img1+"'/></li>"
		                 imgb +="<li><img src='"+data[i].img2+"'/></li>"
		                 //imgb +="<li><img src="+data[i].img2+"/></li>"
		                 imgb +='</ul>'
		                 imgs +='<ul>'
		                 imgs +="<li><img src='"+data[i].img1+"'/></li>"
		                 imgs +="<li><img src='"+data[i].img2+"'/></li>"
		                 imgs +='</ul>'
		                 pri += data[i].price
		                 bu   +="<a class='buy-now' dataid='"+data[i].id+"' href='javascript:;'>"+data[i].buy+"</a>"
		                 ba   +="<a class='buy-bag' href='javascript:;'>"+data[i].bag+"</a>"
		                 jifen +="<b>"+data[i].jf+"</b>"
		                 
		                 fdj +='<ul class="fdj">'
		                 fdj +="<li><img src='"+data[i].img1+"'/></li>"
		                 fdj +="<li><img src='"+data[i].img2+"'/></li>"
		                 fdj +='</ul>'
		                }
		   	   			
		   	   	    }
		   	   		$("#content .lefto .sh .span2").append(str)
		   	   		$("#content .righto .ritop .pinpai em").append(str)
		   	   		$("#content .lefto .tupian .dtp").append(imgb)
		   	   		$("#content .lefto .xia .xtp").append(imgs)
		   	   		$("#content .righto .rimin .jiage").append(pri)
                    $("#content .buy-btn .buy1").append(bu)
		   	   		$("#content .buy-btn .buy2").append(ba)
		   	   		$("#content .zeng .jf").append(jifen)
		   	   		$("#content .xia" ).append(fdj)
		   	   		dsfds()
		}   		
	})         
})
function dsfds(){
	$(".buy-btn").on("click",".buy-now",function(){
				var thisjiage=$(this).parents("#content").find(".jiage").html()
				alert(thisjiage)
	   	   	   var dataid =$(this).attr("dataid");
	   	   	   var num = $(this).parents('#content').find('.total-num').val();
	   	   	   //alert(num)
	   	   	   if(getCookie(''+dataid)){
		   	   	   	setCookie('dataid',dataid)
		   	   	   	var oldnum = getCookie('n'+dataid);
		   	   	   	//alert(oldnum);
		   	   	   //	var newnum = Number(num)+Number(oldnum);
		   	   	   //	alert(newnum);
		   	   	   var day = setCookieDate(1)
		   	   	  // alert(day)
		   	   	   	setCookie("n"+dataid,oldnum,day,"/")
		   	   	   	setCookie("thisjiage",thisjiage)
		   	   	   	 window.location.href="gwc.html";
	   	   	   }else{
	   	   	   setCookie('dataid',dataid,day,"/")
	   	   	   setCookie("n"+dataid,num,day,"/")
	   	   	   	setCookie("thisjiage",thisjiage)
	   	   	   window.location.href="gwc.html";
	   	   	   }
	   	   	  
	   	   })
}

